﻿using UnityEngine;
using UnityEngine.UI;

public class LevelButton : MonoBehaviour
{
    public Sprite current, locked, passed;
    public Image image;

    void Start()
    {
        int index = transform.GetSiblingIndex();
        GetComponentInChildren<Text>().text = (index + 1).ToString();

        if (index == Prefs.UnlockedLevel)
        {
            image.sprite = current;
        }
        else if (index > Prefs.UnlockedLevel)
        {
            image.sprite = locked;
            GetComponent<Button>().interactable = false;
        }
        else
        {
            image.sprite = passed;
        }
    }

    public void OnButtonClick()
    {
        Prefs.CurrentLevel = transform.GetSiblingIndex();
        CUtils.LoadScene(2, true);
    }
}
